// hyb_yl/zhuanjiasubpages/pages/zhifuend/zhifuend.js
var app = getApp()
var interval;
var time1 = null
Page({

  /**
   * 页面的初始数据
   */
  data: {
    pjxing: 0,
    txt: "",
    pingjia: false, //评价弹框
    pjvalue: "",
    sendlist: ["问诊异常通知", "问诊提醒", "医护服务动态提醒"],
    applyFor: false,
    popshow: false,
    shouwtab: false,
    upload_picture_list: [],
    typedate: 0,
    msgmb: 'yes',
    tid: '',
    imgs: [
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
      "https://img1.dxycdn.com/2020/0308/949/3400928984622785985-22.jpg",
    ]
  },
  big_img: function (e) {
    var imgList = e.currentTarget.dataset.imglist
    var img = e.currentTarget.dataset.img
    console.log(e)
    console.log(imgList)
    wx.previewImage({
      urls: imgList,
      current: img
    })
  },
  //查看报告
  lookreport(e) {
    // let status = e.currentTarget.dataset.status
    // if (status == 1) {
    //   wx.navigateTo({
    //     url: '/hyb_yl/mysubpages/pages/report_detail/report_detail',
    //   })
    // } else {d
    //   wx.navigateTo({
    //     url: '/hyb_yl/mysubpages/pages/diagReport/diagReport',
    //   })
    // }
    var that = this
    var id = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/diagReport/diagReport?id=' + id + '&ifzj=0',
    })
  },
  //关闭评价
  closepj() {
    this.setData({
      pingjia: false
    })
  },
  //关闭追问
  closezhuiwen() {
    this.setData({
      shouwtab: false
    })
  },
  tabinput(e) {
    this.setData({
      shouwtab: !this.data.shouwtab
    })
  },
  xing(e) {
    let num = e.currentTarget.dataset.dex
    this.setData({
      pjxing: num * 1 + 1
    })
  },
  addxing(e) {
    let num = e.currentTarget.dataset.dex,
      fen = this.data.pjxing
    let pf = num * 1 + fen * 1 + 1
    this.setData({
      pjxing: pf
    })
  },
  pjtextarea(e) {
    this.setData({
      pjvalue: e.detail.value
    })
  },
  //提交
  submitpj() {
    let num = this.data.pjxing,
      val = this.data.pjvalue
    this.setData({
      pingjia: false
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    wx.showNavigationBarLoading();
    var that = this
    var zid = options.zid
    var back_orser = options.back_orser
    var bgc = wx.getStorageSync('color')
    var key_words = options.key_words
    var j_id = options.j_id
    var orders = options.back_orser
    var ifpay = options.ifpay
    var money = options.money
    var currentData = options.currentData
    var tid = options.tid
    if (options.tid && options.tid !== 'undefined') {
      that.setData({
        tid: options.tid
      })
    } else {
      that.setData({
        tid: ''
      })
    }
    if (options.ifgb) {
      var ifgb = options.ifgb
      that.setData({
        ifgb: ifgb
      })
    }
    console.log(options.id)
    if (options.id) {
      var id = options.id
      that.setData({
        id: id
      })
    }
    console.log(that.data.id)
    if (options.c_id) {
      var c_id = options.c_id
      that.setData({
        c_id: c_id
      })
    }
    //查询所有上传的报告
    app.util.request({
      'url': 'entry/wxapp/user.tijianorder',
      data: {
        id: options.id,
        openid: wx.getStorageSync('openid'),
      },
      success: function (res) {
        console.log(res)
        that.setData({
          bglist: res.data
        })
      }

    })
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    //获取订阅消息id
    app.util.request({
      'url': 'entry/wxapp/index.techen',
      success: function (res) {
        console.log(res)
        var msg = res.data.wxapp_mb
        that.setData({
          submitOrder: msg.submitOrder, //就诊提醒
          OpenHalfcard: msg.OpenHalfcard, //用药提醒提醒
          Mobile: msg.Mobile, //问诊提醒（提醒患者，提醒医生通用）
          hexiao: msg.hexiao, //问诊状态提醒退款不接诊等等
          spstratSuccess: msg.spstratSuccess,
          cfoverfcard: msg.cfoverfcard,
          fwSuccess: msg.fwSuccess
        })
      }
    })
    app.util.request({
      'url': 'entry/wxapp/user.detail',
      data: {
        j_id: j_id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          usedetail: res.data
        })
      }
    })
    app.util.request({
      'url': 'entry/wxapp/hzbingli.url',
      success: function (res) {
        console.log(res)
        that.setData({
          url: res.data,
        })
      }
    })
    if (options.txt) {
      this.setData({
        txt: options.txt,
        popshow: options.txt == 'yes' ? true : false
      })
    }
    //查询是否有当前订单的公开问题
    app.util.request({
      'url': 'entry/wxapp/user.answeropen',
      data: {
        orders: back_orser
      },
      success: function (res) {
        console.log(res)
        if (res.data.status == 1) {
          that.setData({
            open: 1
          })
        }
        if (res.data.status == 0) {
          that.setData({
            open: 0
          })
        }
        if (!res) {
          that.setData({
            open: 0
          })
        }
        // that.setData({
        //   id: res.data.id
        // })
      }
    })
    that.setData({
      zid: zid,
      back_orser: back_orser,
      key_words: key_words,
      j_id: j_id,
      ifpay: ifpay,
      money: money,
      orders: orders,
      currentData: currentData
    })
    let userInfo = wx.getStorageSync('userInfo')
    that.setData({
      u_name: userInfo.u_name,
      u_thumb: userInfo.u_thumb
    })
  },
  quitclick() {
    this.setData({
      popshow: false,
      applyFor: false
    })
  },
  allowbtn() {
    this.setData({
      popshow: false,
      applyFor: false,
      txt: ""
    })
  },
  onHide: function () {
    clearInterval(time1)
  },
  // 调取申请
  ptiontitbtn(e) {
    console.log(e)
    var that = this
   
    var spstratSuccess = that.data.spstratSuccess
    var OpenHalfcard = that.data.OpenHalfcard
    var Mobile = that.data.Mobile
    var hexiao = that.data.hexiao
    var cfoverfcard = that.data.cfoverfcard
    var fwSuccess = that.data.fwSuccess;
    console.log(cfoverfcard)
    console.log(fwSuccess)
    wx.requestSubscribeMessage({
      tmplIds: [spstratSuccess, cfoverfcard, fwSuccess],
      success: (res) => {
        console.log(res)
        //调用授权
      },
      fail: function (res) {
        console.log(res)
      }
    })
    this.setData({
      applyFor: true,
      msgmb: 'non',
      popshow: false
    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    wx.showNavigationBarLoading();
    this.getchufang()
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    var that = this
    var ifgb = that.data.ifgb
    var tid = that.data.tid
    if (ifgb == 0) {
      that.getUptotime()
    }
    if (tid!=='') {

    }else{
      that.getUserchar()
    }
    
    wx.showNavigationBarLoading();
  },


  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    clearInterval(time1)
    var that = this
    var currentData = that.data.currentData
    var pages = getCurrentPages();
    var prevPage = pages[pages.length - 2];
    that.setData({
      currentData: currentData
    })
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  //查询当前用户与医生的图文记录
  getUserchar() {
    var that = this
    var zid = that.data.zid
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    //图文
    if (key_words == 'tuwenwenzhen') {
      app.util.request({
        'url': 'entry/wxapp/tuwen.listall',
        data: {
          zid: zid,
          back_orser: back_orser,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          console.log(res)
          if (res.data.length !== 0) {
            that.setData({
              id: res.data[0].id
            })
          }
          var list = res.data
          that.setData({
            list: res.data,
            ifpay: list[0].ifpay,
            ifgb: list[0].ifgb,
            addnum: parseInt(list[0].addnum)
          })
        }
      })
    }
    //电话
    if (key_words == 'dianhuajizhen' || key_words == 'shipinwenzhen' || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      app.util.request({
        'url': 'entry/wxapp/yuyue.dianhualistall',
        data: {
          zid: zid,
          back_orser: back_orser,
          key_words: key_words,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          console.log(res)
          var list = res.data
          that.setData({
            list: res.data,
            ifpay: list[0].ifpay,
            ifgb: list[0].ifgb,
            id:list[0].id,
            addnum: parseInt(list[0].addnum)
          })
        }
      })
    }
    //txt=yes&zid=16&back_orser=14833566621595404637&key_words=yuanchengkaifang&j_id=60&overtime=1595404817
    //处方
    if (key_words == 'yuanchengkaifang') {
      app.util.request({
        'url': 'entry/wxapp/yuyue.cflistall',
        data: {
          zid: zid,
          back_orser: back_orser,
          key_words: key_words,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          console.log(res.data);
          var list = res.data;

          //新增开始
          that.setData({
            ifpay: list[0].ifpay,
            ifgb: list[0].ifgb,
            
          })
          //新增结束



          if (res.data.length !== 0) {
            that.setData({
              id: res.data[0].c_id
            })
          }
          that.setData({
            list: res.data,
            addnum: parseInt(list[0].addnum)
          })
        }
      })
    }
    //挂号
    if (key_words == 'yuanchengguahao') {
      app.util.request({
        'url': 'entry/wxapp/yuyue.guahaolistall',
        data: {
          zid: zid,
          back_orser: back_orser,
          key_words: key_words,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          //console.log(res)
          var list = res.data
          that.setData({
            list: res.data,
            ifpay: list[0].ifpay,
            ifgb: list[0].ifgb,
            id:list[0].id,
          })
        }
      })
    }
  },
  uploadimg: function () {
    let that = this;
    var uniacid = app.siteInfo.uniacid
    var data_arr = that.data.upload_picture_list;
    wx.chooseImage({
      count: 5,
      sizeType: ['original', 'compressed'],
      sourceType: ['album', 'camera'],
      success(res) {
        // tempFilePath可以作为img标签的src属性显示图片
        const tempFilePaths = res.tempFilePaths
        for (var i = 0; i < tempFilePaths.length; i++) {
          wx.uploadFile({
            url: that.data.url + 'app/index.php?i=' + uniacid + '&c=entry&a=wxapp&do=Uploadback&m=hyb_yl',
            filePath: tempFilePaths[i],
            name: 'upfile',
            formData: [],
            success: function (res) {
              console.log(res)
              data_arr.push(res.data)
              that.setData({
                upload_picture_list: data_arr,
                typedate: 1
              })
            }
          })
        }
      }
    })
  },
  clearImg: function (e) {
    var that = this;
    var index = e.currentTarget.dataset.ind;
    console.log(index);
    var nowList = []; //新数据
    var imglis = that.data.upload_picture_list; //原数据
    imglis.splice(index, 1);
    that.setData({
      upload_picture_list: imglis
    })
  },
  submitformzw(e) {
    var that = this;
    var val = e.detail.value.zhuiwen;
    var upload_picture_list = that.data.upload_picture_list
    var zid = that.data.zid
    var typedate = that.data.typedate
    var orders = that.data.back_orser
    var key_words = that.data.key_words
    var addnum = parseInt(that.data.addnum)
    if (that.data.id) {
      var id = that.data.id
    }
    if (key_words == 'shipinwenzhen' || key_words == 'dianhuajizhen' || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      if (key_words == 'dianhuajizhen') {
        var near = "电话"
      }
      if (key_words == 'shipinwenzhen') {
        var near = "视频"
      }
      if (key_words == 'tijianjiedu') {
        var near = "报告解读"
      }
      if (key_words == 'shoushukuaiyue') {
        var near = "手术快约"
      }
      var arr = {
        'text': val,
        'typedate': typedate,
        'upload_picture_list': upload_picture_list,
      }
      app.util.request({
        'url': 'entry/wxapp/yuyue.adduserzhuiwen',
        data: {
          arr: arr,
          orders: orders,
          zid: zid,
          keywords: key_words,
          addnum: addnum
        },
        success: function (res) {
          console.log(res)
          that.getUserchar()
          that.setData({
            shouwtab: false
          })
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
            data: {
              id: id,
              val: val,
              near: near,
              zid: zid,
              type:"zj"
            },
            success: function (res) {
              console.log(res)
            }
          })
        }
      })
    }
    if (key_words == 'yuanchengguahao') {
      if (key_words == 'yuanchengguahao') {
        var near = "在线挂号"
      }
      var arr = {
        'text': val,
        'typedate': typedate,
        'upload_picture_list': upload_picture_list,
      }
      app.util.request({
        'url': 'entry/wxapp/yuyue.addguahaozhuiwen',
        data: {
          arr: arr,
          orders: orders,
          zid: zid,
          keywords: key_words,
          addnum: addnum
        },
        success: function (res) {
          console.log(res)
          that.getUserchar()
          that.setData({
            shouwtab: false
          })
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
            data: {
              id: id,
              val: val,
              near: near,
              zid: zid,
              type:"zj"
            },
            success: function (res) {
              console.log(res)
            }
          })
        }
      })
    }
    if (key_words == 'tuwenwenzhen') {
      var arr = {
        'text': val,
        'typedate': typedate,
        'upload_picture_list': upload_picture_list,
      }
      app.util.request({
        'url': 'entry/wxapp/Zhuanjia.adduserzhuiwen',
        data: {
          arr: arr,
          orders: orders,
          zid: zid,
          grade: 2,
          addnum: addnum
        },
        success: function (res) {
          console.log(res)
          that.getUserchar()
          that.setData({
            shouwtab: false
          })
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
            data: {
              id: id,
              val: val,
              near: '图文',
              zid: zid,
              type:"zj"
            },
            success: function (res) {
              console.log(res)
            }
          })
        }
      })
    }
    if (key_words == 'yuanchengkaifang') {

      var arr = {
        'text': val,
        'text2': '',
        'timleng': '',
        'typedate': typedate,
        'upload_picture_list': upload_picture_list,
      }
      app.util.request({
        'url': 'entry/wxapp/user.addcfzhuiwen',
        data: {
          arr: arr,
          orders: orders,
          zid: zid,
          keywords: key_words,
          role: 0,
          addnum: addnum
        },
        success: function (res) {
          console.log(res)
          that.getUserchar()
          that.setData({
            shouwtab: false
          })
          app.util.request({
            'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
            data: {
              id: id,
              val: val,
              near: '开处方',
              zid: zid,
              type:"zj"
            },
            success: function (res) {
              console.log(res)
            }
          })
        }
      })
    }
  },
  buttonclick: function (e) {
    var that = this
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    var open = e.currentTarget.dataset.open
    var id = e.currentTarget.dataset.id
    var ifpay = that.data.ifpay
    // if (key_words == 'tijianjiedu') {
    //   var itemList = ['删除订单', '上传报告']
    //   wx: wx.showActionSheet({
    //     itemList: itemList,
    //     itemColor: '',
    //     success: function (res) {
    //       if (res.tapIndex == 0) {
    //         if (!res.cancel) {
    //           wx.showModal({
    //             title: '是否删除订单？',
    //             content: '删除后不可恢复',
    //             success: (result) => {
    //               if (result.confirm) {
    //                 app.util.request({
    //                   'url': 'entry/wxapp/user.delwzorder_two',
    //                   data: {
    //                     back_orser: back_orser
    //                   },
    //                   success: function (res) {
    //                     console.log(res)
    //                     wx.showToast({
    //                       title: '删除成功',
    //                       icon: 'none',
    //                       success: (res) => {
    //                         setTimeout(function () {
    //                           wx.navigateBack({
    //                             detail: 1
    //                           })
    //                         }, 2000)
    //                       },
    //                     })
    //                   }

    //                 })

    //               }
    //             },
    //           })
    //         }
    //       } else {
    //         //上传报告
    //         if (that.data.open == 1) {

    //         }

    //       }

    //     },
    //     fail: function (res) {},
    //     complete: function (res) {},
    //   })
    //   return false
    // }
    if (open == 0) {
      var msg = '取消公开'
    } else {
      var msg = '公开问题'
    }
    if (ifpay == '3' || ifpay == '2') {
      var itemList = ['删除订单', msg]
    } else {
      var itemList = ['删除订单']

    }
    wx: wx.showActionSheet({
      itemList: itemList,
      itemColor: '',
      success: function (res) {
        if (res.tapIndex == 0) {
          if (!res.cancel) {
            wx.showModal({
              title: '是否删除订单？',
              content: '删除后不可恢复',
              success: (result) => {
                if (result.confirm) {
                  app.util.request({
                    'url': 'entry/wxapp/user.delwzorder_two',
                    data: {
                      back_orser: back_orser
                    },
                    success: function (res) {
                      console.log(res)
                      wx.showToast({
                        title: '删除成功',
                        icon: 'none',
                        success: (res) => {
                          setTimeout(function () {
                            wx.navigateBack({
                              detail: 1
                            })
                          }, 2000)
                        },
                      })
                    }

                  })

                }
              },
            })
          }
        } else {
          //公开问题
          if (that.data.open == 1) {
            app.util.request({
              'url': 'enter/wxapp/user.openquestion',
              data: {
                back_orser: back_orser,
                key_words: key_words,
                id: id
              },
              success: function (res) {
                console.log(res)
                //查询是否有当前订单的公开问题
                app.util.request({
                  'url': 'entry/wxapp/user.answeropen',
                  data: {
                    orders: back_orser
                  },
                  success: function (res) {
                    console.log(res)
                    if (res.data.status == 1) {
                      that.setData({
                        open: 1,
                        id: res.data.id,
                        status: res.data.status
                      })
                    } else {
                      that.setData({
                        open: 0,
                      })
                    }
                  }
                })
              }
            })
          } else {
            wx.showModal({
              title: '是否公开问题？',
              content: '公开问题帮助更多人',
              success: function (res) {
                console.log(res)
                if (res.confirm) {
                  app.util.request({
                    'url': 'enter/wxapp/user.openquestion',
                    data: {
                      back_orser: back_orser,
                      key_words: key_words,
                      id: id
                    },
                    success: function (res) {
                      console.log(res)
                      //查询是否有当前订单的公开问题
                      app.util.request({
                        'url': 'entry/wxapp/user.answeropen',
                        data: {
                          orders: back_orser
                        },
                        success: function (res) {
                          console.log(res)
                          if (res.data.status == 1) {
                            that.setData({
                              open: 1,
                              id: res.data.id,
                              status: res.data.status
                            })
                          } else {
                            that.setData({
                              open: 0,
                            })
                          }
                        }
                      })
                    }
                  })
                }
              }
            })
          }

        }

      },
      fail: function (res) {},
      complete: function (res) {},
    })
  },

  getchufang() {
    var that = this
    var zid = that.data.zid
    var back_orser = that.data.back_orser
    var c_id = that.data.c_id
    //console.log(c_id)
    app.util.request({
      'url': 'entry/wxapp/zhuanjia.chufangcont',
      data: {
        back_orser: back_orser,
        c_id: that.data.c_id
      },
      success: function (res) {
        console.log(res)
        that.setData({
          cfdata: res.data
        })
      }
    })
  },
  lookdetail(e) {
    var that = this
    var id = e.currentTarget.dataset.id
    var orderStatus = e.currentTarget.dataset.orderstatus
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/chufangjianyi/chufangjianyi?id=' + id + '&orderStatus=' + orderStatus + '&xufang=1',
    })
  },
  atbuy(e) {
    var that = this
    var c_id = e.currentTarget.dataset.c_id
    var cartlist = JSON.stringify(e.currentTarget.dataset.cartlist)
    var orders = e.currentTarget.dataset.orders
    var j_id = e.currentTarget.dataset.j_id
    var text = e.currentTarget.dataset.text
    var zhenduan = e.currentTarget.dataset.zhenduan
    var yongyao = e.currentTarget.dataset.yongyao
    var money = e.currentTarget.dataset.totals
    var ifzj = 0
    var goodsid = e.currentTarget.dataset.id
    wx.navigateTo({
      url: '/hyb_yl/backstageServices/pages/yizhu/yizhu?role=0&cartlist=' + cartlist + '&j_id=' + j_id + '&text=' + text + '&zhenduan=' + zhenduan + '&yongyao=' + yongyao + '&orders=' + orders + '&money=' + money + '&ifzj=' + ifzj + '&goodsid=' + goodsid
    })
  },
  sqchufang(e) {
    var that = this
    var j_id = that.data.j_id
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    var zid = that.data.zid
    wx.reLaunch({
      url: '/hyb_yl/czhuanjiasubpages/pages/chufangmes/chufangmes?tit=远程开方&key_words=yuanchengkaifang' + '&back_orser=' + back_orser + '&zid=' + zid + '&j_id=' + j_id,
    })
  },
  tabinputpay(e) {
    console.log(e)
    var that = this
    var back_orser = that.data.back_orser
    var money = that.data.money
    var key_words = that.data.key_words
    var zid = that.data.zid
    console.log(back_orser, money, key_words, zid)
    app.util.request({
      'url': 'entry/wxapp/yuyue.paywenzhen',
      header: {
        "Content-Type": "application/xml"
      },
      method: "GET",
      data: {
        openid: wx.getStorageSync('openid'),
        z_tw_money: money,
        orders: back_orser,
        key_words: key_words
      },
      success: function (res) {
        console.log(res);
        wx.requestPayment({
          'timeStamp': res.data.timeStamp,
          'nonceStr': res.data.nonceStr, //字符串随机数
          'package': res.data.package,
          'signType': res.data.signType,
          'paySign': res.data.paySign,
          success: function (res) {
            console.log(res)
            if (key_words == 'yuanchengkaifang') {
              app.util.request({
                'url': 'entry/wxapp/zhuanjia.getdocmbtxing',
                data: {
                  val: '处方订单提醒',
                  near: '开处方',
                  zid: zid
                },
                success: function (res) {
                  console.log(res)
                }
              })
            }
          },
          fail: function (res) {
            console.log(res)
          },
          'complete': function (res) {
            clearInterval(time1)
            if (res.errMsg == 'requestPayment:ok') {
              wx.showModal({
                title: '提示',
                content: '支付成功'
              });
              that.getOrderdetail()
            }
            return;
          }
        })
      }
    })
  },
  tuikuan(e) {
    console.log(e)
    var that = this
    var back_orser = that.data.back_orser
    var key_words = that.data.key_words
    var money = that.data.money
    if (money == '0.00') {
      var title = "是否取消问诊"
    } else {
      var title = "是否申请退款"
    }
    wx.showModal({
      title: title,
      success(res) {
        if (res.confirm) {
          app.util.request({
            'url': 'entry/wxapp/user.twtuikuan',
            data: {
              back_orser: back_orser,
              money: money,
              keywords: that.data.key_words
            },
            success: function (res) {
              console.log(res)
              //消息通知
              app.util.request({
                'url': 'entry/wxapp/zhuanjia.tktemplet',
                data: {
                  orders: back_orser,
                  money: money,
                  keywords: that.data.key_words
                },
                success: function (res) {
                  console.log(res)
                }
              })

              wx.showToast({
                title: '申请成功，待审核',
                icon: 'none',
                success: function (res) {
                  console.log(res)
                  wx.navigateBack({
                    detail: 1
                  })
                }
              })
            }
          })
        }
      }
    })
  },
  tabtwoinput() {
    var that = this
    wx.reLaunch({
      url: '/hyb_yl/czhuanjiasubpages/pages/zhuanjiazhuye/zhuanjiazhuye?zid=' + that.data.zid,
    })
  },
  getOrderdetail() {
    var that = this
    var orders = that.data.orders
    var key_words = that.data.key_words
    //console.log(key_words)
    if (key_words == 'tuwenwenzhen') {
      //图文问诊单独订单详情
      app.util.request({
        'url': 'entry/wxapp/yuyue.detail',
        data: {
          orders: orders,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          console.log(res)
          wx.showNavigationBarLoading();
          that.setData({
            detail: res.data,
            addnum: parseInt(res.data.addnum),
            money: res.data.money,
            ifgb: res.data.ifgb
          })

        }
      })
    }
    if (key_words == 'dianhuajizhen' || key_words == 'shipinwenzhen' || key_words == 'tijianjiedu' || key_words == 'shoushukuaiyue') {
      //电话问诊单独订单详情
      app.util.request({
        'url': 'entry/wxapp/yuyue.getwenzhendetail',
        data: {
          orders: orders,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          //console.log(res)
          that.getSetotime(res.data.overtime)
          wx.showNavigationBarLoading();
          that.setData({
            detail: res.data,
            addnum: parseInt(res.data.addnum),
            money: res.data.money,
            ifpay: res.data.ifpay
          })
          wx.showNavigationBarLoading();
        }
      })
    }

    if (key_words == 'yuanchengkaifang') {
      //处方问诊单独订单详情
      app.util.request({
        'url': 'entry/wxapp/yuyue.getordercfdetail',
        data: {
          orders: orders,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          // console.log(res)
          that.getSetotime(res.data.overtime)
          wx.showNavigationBarLoading();
          that.setData({
            cfdetail: res.data,
            addnum: parseInt(res.data.addnum),
            money: res.data.money,
            ifgb: res.data.ifgb,
            ifpay: res.data.ispay
          })
          wx.showNavigationBarLoading();
        }
      })
    }
    //挂号
    if (key_words == 'yuanchengguahao') {
      app.util.request({
        'url': 'entry/wxapp/yuyue.getguahaohendetail',
        data: {
          orders: orders,
          openid: wx.getStorageSync('openid'),
        },
        success: function (res) {
          that.getSetotime(res.data.overtime)
          wx.showNavigationBarLoading();
          that.setData({
            detail: res.data,
            addnum: parseInt(res.data.addnum),
            money: res.data.money,
            ifpay: res.data.ifpay
          })
          wx.showNavigationBarLoading();
        }
      })
    }
  },
  getSetotime(overtime) {
    wx.showNavigationBarLoading();
    var that = this
    var overtime = overtime
    var time3 = overtime.split('-')
    var time4 = time3.join('/')
    var date1 = new Date(time4)
    var ifpay = that.data.ifpay
    var date = new Date()
    var key_words = that.setData.key_words
    var sheyuTime = Date.parse(date1) - Date.parse(date)
    var money = that.data.money;
    let hours = parseInt((sheyuTime % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
    let minutes = parseInt((sheyuTime % (1000 * 60 * 60)) / (1000 * 60));
    let seconds = (sheyuTime % (1000 * 60)) / 1000;
    if (ifpay == '0' || ifpay == '1' || ifpay == '2') {
      that.setData({
        dumiao: hours + ":" + minutes + ":" + seconds
      })
    }
    wx.showNavigationBarLoading();
    if (sheyuTime == 0) {
      clearInterval(time1)
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.dopagetime',
        data: {
          orders: that.data.orders,
          ifpay: that.data.ifpay,
          key_words: that.data.key_words
        },
        success: function (res) {
          console.log(res)
          console.log(that.data.ifpay);
          console.log(ziti);
          if (that.data.ifpay == '2') {
            if (ziji == 0) {
              app.util.request({
                'url': 'entry/wxapp/tuike.uptopmoney',
                data: {
                  tkid: tkid,
                  mytkid: mytkid,
                  money: money,
                  openid: wx.getStorageSync('openid'),
                  leixing: that.data.key_words,
                  orders: that.data.orders
                },
                success: function (res) {
                  console.log(res)
                }
              })
            }
            app.util.request({
              'url': 'entry/wxapp/yuyue.fanlis',
              data: {
                back_orser: that.data.orders,
                keywords: that.data.key_words,
                openid: wx.getStorageSync('openid')
              },
              success: function (res) {
                console.log(res)

              }
            })
          }
          wx.showToast({
            title: '订单已结束',
            icon: 'none',
            success: function () {

              setTimeout(function () {

                // wx.navigateBack({
                //   detail: 1
                // }, 1500)
                if (key_words == 'dianhuajizhen') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'shipinwenzhen') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'tijianjiedu') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/unscramble/unscramble?key_words=' + key_words,
                  })
                }
                if (key_words == 'shoushukuaiyue') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'yuanchengguahao') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/my_dingdan1/my_dingdan1?key_words=' + key_words,
                  })
                }
                if (key_words == 'tuwenwenzhen') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'yuanchengkaifang') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
              }, 1500)
            }
          })
        }
      })
      return false
    }
    if (sheyuTime <= 0) {
      clearInterval(time1)
      that.setData({
        dumiao: "00:00:00"
      })
      app.util.request({
        'url': 'entry/wxapp/zhuanjia.dopagetime',
        data: {
          orders: that.data.orders,
          ifpay: that.data.ifpay,
          key_words: that.data.key_words
        },
        success: function (res) {
          wx.showToast({
            title: '订单已结束',
            icon: 'none',
            success: function () {

              setTimeout(function () {
                if (key_words == 'dianhuajizhen') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'shipinwenzhen') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'tijianjiedu') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/unscramble/unscramble?key_words=' + key_words,
                  })
                }
                if (key_words == 'shoushukuaiyue') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'yuanchengguahao') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/my_dingdan1/my_dingdan1?key_words=' + key_words,
                  })
                }
                if (key_words == 'tuwenwenzhen') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
                if (key_words == 'yuanchengkaifang') {
                  wx.reLaunch({
                    url: '/hyb_yl/mysubpages/pages/wodezixun/wodezixun?key_words=' + key_words,
                  })
                }
              }, 1500)
            }
          })
        }
      })
      wx.showNavigationBarLoading();
    }
  },
  getUptotime() {
    var that = this
    wx.showNavigationBarLoading();
    var ifpay = that.data.ifpay
    if (ifpay == 0 || ifpay == 1 || ifpay == 2) {
      time1 = setInterval(function () {
        that.getUserchar()
        that.getOrderdetail()
        that.getchufang()
      }, 1000)
    }
    wx.showNavigationBarLoading();
  },
})